using System;
using System.Collections.Generic;
using System.Text;

using SdlDotNet.Graphics;
using SdlDotNet.Graphics.Sprites;
using System.Drawing;
using SdlDotNet.Core;
using SdlDotNet.Input;
using SnakeCharp.Game;
using SnakeCharp.Interfaces;
using SnakeCharp.UI;

namespace SnakeCharp.Entity
{
    public class Mouse : BaseEntity, IEatable
    {
        private UIFont hudText;
        private int points;
        private bool isEaten;

        public Mouse(int x, int y)
        {
            SetupAnimations("Mouse1.png");

            this.X = x;
            this.Y = y;
            this.isEaten = false;


            this.hudText = new UIFont("Points", 10);
            this.hudText.Transparent = true;
            this.hudText.TransparentColor = Color.Black;
            this.hudText.Color = Color.Green;
            this.hudText.BackgroundColor = Color.Black;

            this.points = 500;
        }



        private void SetupAnimations(string name)
        {
            //Load the Sprite 
            string spritedir = Configurations.ImagePath + name;

            //Load the Image to a Surface
            Surface image = new Surface(spritedir);

            //TEST: Make it Hardware surface
            //image.Transparent = true;
            //image.TransparentColor = Color.White;
            //image = image.Convert();

            //Load the Surface to a Sufrace Collection
            SurfaceCollection item = new SurfaceCollection();
            for (int i = 0; i < (image.Height / 40); i++)
            {
                item.Add(image, new Size(50, 40), i);
            }

            #region SurfaceCollections

            //Adds the Default Animation
            SurfaceCollection defaultCollection = new SurfaceCollection();

            for (int i = 0; i < 1; i++)
            {
                defaultCollection.Add(item[i], new Size(50, 40));
            }


            #endregion

            #region AnimationCollections
            //Adds the Default Animation
            AnimationCollection defaultAnimation = new AnimationCollection();
            defaultAnimation.Add(defaultCollection, 500);


            this.Animations.Add("Default", defaultAnimation);

            #endregion

            this.CurrentAnimation = "Default";
        }

        #region Overriden Methods
        public override void Update()
        {
            if (this.points >= 10)
            {
                if (this.points < 200)
                    this.hudText.Color = Color.Red;
                else if(this.points < 350)
                    this.hudText.Color = Color.Yellow;
                
                this.hudText.Text = "Points: " + this.points--; //Only for test
            }
        }

        public override void Render(float interpolation, Surface distination)
        {
            distination.Blit(this, this.Rectangle);
            distination.Blit(this.hudText, new Point(this.Position.X, this.Bottom));
        } 
        #endregion

        #region IEatable Members

        public void ActOponCollision(object collisionObject)
        {
            if (collisionObject is Snake)
            {
                this.isEaten = true;
            }
        }

        public bool IsEaten
        {
            get { return this.isEaten; }
        }

        public int Points
        {
            get { return this.points; }
        }

        #endregion
    }
}
